package org.example.web;

import org.example.domain.User;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

@RestController
public class UserController {
    //加载端口 (这种写法，是直接从application.yml中读取配置信息)
    @Value("${server.port}")
    private int port;

    @GetMapping("/user/getinfo")
    public User getInfo() {
        User user = new User();
        user.setId(1001L);
        user.setUsername("运行端口号是：" + port);
        user.setDesc("这是一个测试描述信息");

        return user;
    }

    @GetMapping("/user/{id}")
    public User getById(@PathVariable("id") Long id) {
        User user = new User();
        user.setId(id);
        user.setUsername("运行端口号是：" + port);
        user.setDesc("这是一个测试描述信息");

        return user;
    }

    @PostMapping("/user/add")
    public User addUser(@RequestBody User user) {
        return user;
    }
}
